package fr.mma.livraison;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import fr.mma.livraison.controller.Factory;
import fr.mma.livraison.controller.DevController;
import fr.mma.livraison.controller.OrderType;

@SuppressWarnings("serial")
public class DevListServlet extends HttpServlet {
	
	public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
		resp.setContentType("application/json");
		final DevController mainController = new DevController();
		final Gson gson = new Gson();
		final String orderBy = req.getParameter("sortBy");
		String json;
		if (orderBy == null) {
			json = gson.toJson(Factory.buildDev(mainController.getAllDev()));
		} else {
			json = gson.toJson(Factory.buildDev(mainController.getAllDev(OrderType.getByValue(orderBy))));
		}
		resp.getWriter().println(json);
	}
}
